import 'package:dancers_map/ctrl/ctrl_spider_dancer_details.dart';
import 'package:dancers_map/network/enum_connect_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:get/get.dart';

class DetailsPage extends StatefulWidget {
  final String detailsId;

  const DetailsPage({super.key, required this.detailsId});

  @override
  State<DetailsPage> createState() => _DetailsPageState();
}

class _DetailsPageState extends State<DetailsPage> {
  @override
  void initState() {
    super.initState();
    SpiderDancerDetailsCtrl.to.queryDancerMD(widget.detailsId);
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: SafeArea(
        child: buildMarkdownView(),
      ),
    );
  }

  Widget buildMarkdownView() {
    return Obx(() {
      var mdState = SpiderDancerDetailsCtrl.to.mdState.value;
      Widget body = Container();
      switch (mdState) {
        case ConnectState.done:
          var dancerMD = SpiderDancerDetailsCtrl.to.mdLive.value;
          body = Markdown(data: dancerMD.md!.content!);
          break;
        case ConnectState.waiting:
        case ConnectState.none:
          break;
        case ConnectState.err:
          break;
      }
      return body;
    });
  }
}
